package com.smackkitty.haikustudio.data;

import java.util.Date;

import android.content.Context;

public class Haiku {
	//Members
	private Long rowId = null;
	private String title = null;
	private String line1 = null;
	private String line2 = null;
	private String line3 = null;
	private Date created_dt = null;
	private Date updated_dt = null;
	private HaikuDataAdapter adapter;
	
	//Properties
	public String getTitle(){ return this.title; }
	public void setTitle(String title){ 
		this.title = title;
		this.updated_dt = new Date();
	}
	
	public String getLine1(){ return this.line1; }
	public void setLine1(String line1){ 
		this.line1 = line1;
		this.updated_dt = new Date();
	}
	
	public String getLine2(){ return this.line2; }
	public void setLine2(String line2){ 
		this.line2 = line2;
		this.updated_dt = new Date();
	}
	
	public String getLine3(){ return this.line3; }
	public void setLine3(String line3){ 
		this.line3 = line1;
		this.updated_dt = new Date();
	}
	
	public boolean isSaved(){
		if(this.rowId == null ){
			return false;
		}else{
			return true;
		}
	}
	public Date getCreationDate() { return this.created_dt; }
	public Date getUpdatedDate() { return this.updated_dt; }
	
	
	//Methods
	public Haiku(Context context){
		this("", "", "", "", context);
	}
	
	public Haiku(String title, String line1, String line2, String line3, Context context){
		this.title = title;
		this.line1 = line1;
		this.line2 = line2;
		this.line3 = line3;
		this.adapter = new HaikuDataAdapter(context);
		this.adapter.open();
	}
	
	public boolean Save(){
		try{
			this.rowId = this.adapter.createRecord("Haiku", this.title, this.line1 + "/" + this.line2 + "/" + this.line3);
			return true;
		}catch(Exception e){
			return false;
		}
	}
	
	public boolean Update(){
		try{
			return this.adapter.updatePoem(this.rowId, this.title, this.line1 + "/" + this.line2 + "/" + this.line3);
		}catch(Exception e){
			return false;
		}
	}
	
	public boolean Delete(){
		try{
			return this.adapter.deletePoem(this.rowId);
		}catch(Exception e){
			return false;
		}
	}
}

